/* eslint-disable */
// @ts-ignore
import { queryOptions, useMutation } from '@tanstack/vue-query';
import type { DefaultError } from '@tanstack/vue-query';
import request from '@/utils/request';
import { CustomRequestOptions } from '@/interceptors/request';

import * as apis from './articleController';
import * as API from './types';

/** 收藏加入 POST /api/article/addCollect */
export function useAddCollectUsingPostMutation(options?: {
  onSuccess?: (value?: API.AjaxResultobject) => void;
  onError?: (error?: DefaultError) => void;
}) {
  const { onSuccess, onError } = options || {};

  const response = useMutation({
    mutationFn: apis.addCollectUsingPost,
    onSuccess(data: API.AjaxResultobject) {
      onSuccess?.(data);
    },
    onError(error) {
      onError?.(error);
    },
  });

  return response;
}

/** 收藏取消 POST /api/article/cancelCollect */
export function useCancelCollectUsingPostMutation(options?: {
  onSuccess?: (value?: API.AjaxResultobject) => void;
  onError?: (error?: DefaultError) => void;
}) {
  const { onSuccess, onError } = options || {};

  const response = useMutation({
    mutationFn: apis.cancelCollectUsingPost,
    onSuccess(data: API.AjaxResultobject) {
      onSuccess?.(data);
    },
    onError(error) {
      onError?.(error);
    },
  });

  return response;
}

/** 文章分类 GET /api/article/cate */
export function categoryUsingGetQueryOptions(options: {
  options?: CustomRequestOptions;
}) {
  return queryOptions({
    queryFn: async ({ queryKey }) => {
      return apis.categoryUsingGet(queryKey[1] as typeof options);
    },
    queryKey: ['categoryUsingGet', options],
  });
}

/** 收藏列表 GET /api/article/collect */
export function collectUsingGetQueryOptions(options: {
  // 叠加生成的Param类型 (非body参数openapi默认没有生成对象)
  params: API.collectUsingGETParams;
  options?: CustomRequestOptions;
}) {
  return queryOptions({
    queryFn: async ({ queryKey }) => {
      return apis.collectUsingGet(queryKey[1] as typeof options);
    },
    queryKey: ['collectUsingGet', options],
  });
}

/** 文章详情 GET /api/article/detail */
export function detailUsingGetQueryOptions(options: {
  // 叠加生成的Param类型 (非body参数openapi默认没有生成对象)
  params: API.detailUsingGETParams;
  options?: CustomRequestOptions;
}) {
  return queryOptions({
    queryFn: async ({ queryKey }) => {
      return apis.detailUsingGet(queryKey[1] as typeof options);
    },
    queryKey: ['detailUsingGet', options],
  });
}

/** 文章列表 GET /api/article/lists */
export function listsUsingGet1QueryOptions(options: {
  // 叠加生成的Param类型 (非body参数openapi默认没有生成对象)
  params: API.listsUsingGET1Params;
  options?: CustomRequestOptions;
}) {
  return queryOptions({
    queryFn: async ({ queryKey }) => {
      return apis.listsUsingGet1(queryKey[1] as typeof options);
    },
    queryKey: ['listsUsingGet1', options],
  });
}
